package org.example.spring_frist.MessageProject.server;

import org.example.spring_frist.MessageProject.model.messageInfo;
import org.example.spring_frist.MessageProject.dao.MessageDao;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

@Service
public class MessageServer {

    @Autowired
    MessageDao messageDao;

    public List<messageInfo> login() {
        return messageDao.selectAllMessages();
    }
    public messageInfo store(@RequestBody messageInfo message) {
        if (!StringUtils.hasLength(message.getI()) || !StringUtils.hasLength(message.getYou())
                || !StringUtils.hasLength(message.getTalk())) {
            return null;
        }
        messageDao.insertMessage(message);
        return message;
    }
}
